using System.ComponentModel.DataAnnotations;

namespace Lzfy_Refund_Service.Models
{
    /// <summary>
    /// 密码更新任务模型
    /// </summary>
    public class PasswordUpdateTask
    {
        /// <summary>
        /// 主键ID
        /// </summary>
        public int Id { get; set; }

        /// <summary>
        /// 任务唯一标识符
        /// </summary>
        [Required]
        [StringLength(36)]
        public string TaskId { get; set; } = string.Empty;

        /// <summary>
        /// 患者ID
        /// </summary>
        [Required]
        [StringLength(50)]
        public string PatientId { get; set; } = string.Empty;

        /// <summary>
        /// 验证码
        /// </summary>
        [Required]
        [StringLength(50)]
        public string VerifyCode { get; set; } = string.Empty;

        /// <summary>
        /// 验证码信息ID（用于软删除指定的验证码记录）
        /// </summary>
        public int? VerifyInfoId { get; set; }

        /// <summary>
        /// 退费密码(MD5加密)
        /// </summary>
        [Required]
        [StringLength(255)]
        public string RefundPassword { get; set; } = string.Empty;

        /// <summary>
        /// 修改者用户名
        /// </summary>
        [Required]
        [StringLength(50)]
        public string Modifier { get; set; } = string.Empty;

        /// <summary>
        /// 修改者证件类型
        /// </summary>
        [StringLength(20)]
        public string? ModifierCardType { get; set; }

        /// <summary>
        /// 修改者证件号码
        /// </summary>
        [StringLength(50)]
        public string? ModifierCardCode { get; set; }

        /// <summary>
        /// 计划执行时间
        /// </summary>
        [Required]
        public DateTime ScheduledTime { get; set; }

        /// <summary>
        /// 任务创建时间
        /// </summary>
        public DateTime CreatedTime { get; set; } = DateTime.Now;

        /// <summary>
        /// 任务状态
        /// </summary>
        [Required]
        [StringLength(20)]
        public string Status { get; set; } = PasswordTaskStatus.Pending;

        /// <summary>
        /// 实际执行时间
        /// </summary>
        public DateTime? ExecutedTime { get; set; }

        /// <summary>
        /// 错误信息
        /// </summary>
        [StringLength(500)]
        public string? ErrorMessage { get; set; }

        /// <summary>
        /// 重试次数
        /// </summary>
        public int RetryCount { get; set; } = 0;

        /// <summary>
        /// 最大重试次数
        /// </summary>
        public int MaxRetryCount { get; set; } = 3;
    }

    /// <summary>
    /// 任务状态常量
    /// </summary>
    public static class PasswordTaskStatus
    {
        /// <summary>
        /// 待执行
        /// </summary>
        public const string Pending = "Pending";

        /// <summary>
        /// 执行中
        /// </summary>
        public const string Executing = "Executing";

        /// <summary>
        /// 已完成
        /// </summary>
        public const string Completed = "Completed";

        /// <summary>
        /// 失败
        /// </summary>
        public const string Failed = "Failed";

        /// <summary>
        /// 已取消
        /// </summary>
        public const string Cancelled = "Cancelled";
    }

    /// <summary>
    /// 创建密码更新任务请求
    /// </summary>
    public class CreatePasswordUpdateTaskRequest
    {
        /// <summary>
        /// 患者ID
        /// </summary>
        [Required]
        [StringLength(50)]
        public string PatientId { get; set; } = string.Empty;

        /// <summary>
        /// 验证码
        /// </summary>
        [Required]
        [StringLength(50)]
        public string VerifyCode { get; set; } = string.Empty;

        /// <summary>
        /// 验证码信息ID（用于软删除指定的验证码记录）
        /// </summary>
        public int? VerifyInfoId { get; set; }

        /// <summary>
        /// 退费密码(MD5加密)
        /// </summary>
        [Required]
        [StringLength(255)]
        public string RefundPassword { get; set; } = string.Empty;

        /// <summary>
        /// 修改者用户名
        /// </summary>
        [Required]
        [StringLength(50)]
        public string Modifier { get; set; } = string.Empty;

        /// <summary>
        /// 修改者证件类型
        /// </summary>
        [StringLength(20)]
        public string? ModifierCardType { get; set; }

        /// <summary>
        /// 修改者证件号码
        /// </summary>
        [StringLength(50)]
        public string? ModifierCardCode { get; set; }
    }

    /// <summary>
    /// 创建密码更新任务响应
    /// </summary>
    public class CreatePasswordUpdateTaskResponse
    {
        /// <summary>
        /// 是否成功
        /// </summary>
        public bool Success { get; set; }

        /// <summary>
        /// 消息
        /// </summary>
        public string Message { get; set; } = string.Empty;

        /// <summary>
        /// 任务ID
        /// </summary>
        public string? TaskId { get; set; }

        /// <summary>
        /// 计划执行时间
        /// </summary>
        public DateTime? ScheduledTime { get; set; }
    }

    /// <summary>
    /// 查询任务状态请求
    /// </summary>
    public class QueryTaskStatusRequest
    {
        /// <summary>
        /// 任务ID
        /// </summary>
        [Required]
        [StringLength(36)]
        public string TaskId { get; set; } = string.Empty;
    }

    /// <summary>
    /// 查询任务状态响应
    /// </summary>
    public class QueryTaskStatusResponse
    {
        /// <summary>
        /// 是否成功
        /// </summary>
        public bool Success { get; set; }

        /// <summary>
        /// 消息
        /// </summary>
        public string Message { get; set; } = string.Empty;

        /// <summary>
        /// 任务信息
        /// </summary>
        public PasswordUpdateTask? Task { get; set; }
    }

    /// <summary>
    /// 取消任务请求
    /// </summary>
    public class CancelTaskRequest
    {
        /// <summary>
        /// 任务ID
        /// </summary>
        [Required]
        [StringLength(36)]
        public string TaskId { get; set; } = string.Empty;
    }

    /// <summary>
    /// 取消任务响应
    /// </summary>
    public class CancelTaskResponse
    {
        /// <summary>
        /// 是否成功
        /// </summary>
        public bool Success { get; set; }

        /// <summary>
        /// 消息
        /// </summary>
        public string Message { get; set; } = string.Empty;
    }
}